package com.xinzhitong.www.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * collection视图相关操作
 *
 * @author 徐鑫
 */
@Repository
public interface CollectionMapper {

    @Select("select * from ${table} where username=#{username}")
    List<Map<String, Object>> selectCollections(@Param("username") String username, @Param("table") String table);

    @Insert("insert into ${table}(username, ${idField}) values(#{username}, #{id})")
    Integer insertCollection(
            @Param("table") String table,
            @Param("idField") String idField,
            @Param("username") String username,
            @Param("id") Integer id
    );

    @Select("select * from ${table} where id=#{id}")
    Map<String, Object> selectCollection(@Param("table") String table, @Param("id") Integer id);

    @Delete("delete from ${table} where username=#{username} and ${idField} in ${range}")
    Integer deleteCollections(@Param("table") String table, @Param("idField") String idField, @Param("username") String username, @Param("range") String range);

}
